package cn.consult.controller.sys.park;

import cn.consult.common.api.CommonResult;
import cn.consult.sys.dao.TPlaceFloorDao;
import cn.consult.sys.entity.TPlaceBuilding;
import cn.consult.sys.entity.TPlaceFloor;
import cn.consult.sys.service.TPlaceBuildingService;
import cn.consult.sys.service.TPlaceFloorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

//园区管理 > 场地管理 （楼层
@RestController
@Api(tags = " 园区管理 > 场地楼层")
@RequestMapping("/park/floor")
public class TPlaceFloorController {

    @Autowired
    TPlaceFloorService tPlaceFloorService;


    @ApiOperation("getFloosByBulidingId => 根据楼栋id查询 楼层信息")
    @GetMapping("/getFloosByBulidingId/{buildingId}")
    public CommonResult getFloosByBulidingId(@PathVariable Long buildingId) {
        List<TPlaceFloor> list = tPlaceFloorService.getFloosByBulidingId(buildingId);
        return CommonResult.success(list);
    }

    @ApiOperation("getFloorAll =>  条件查询楼层")
    @GetMapping("/getFloorAll")
    public CommonResult getFloorAll(@RequestParam Map<String, Object> params) {
        List<TPlaceFloor> floors = tPlaceFloorService.selectByBuildingNameOrNumber(params);
        return CommonResult.success(floors);
    }

    @ApiOperation("getFloorByNumber =>  楼层名称不能一样")
    @GetMapping("/getFloorByNumber")
    public CommonResult getFloorByNumber(String number, String bulidingId) {
        boolean flag = tPlaceFloorService.flagName(number, bulidingId);
        if (flag) {
            return CommonResult.success();

        }
        return CommonResult.failed("楼层名称不能一样!");
    }

    @ApiOperation("addFloor =>  添加楼层")
    @PostMapping("/addFloor")
    public CommonResult addFloor(@RequestBody TPlaceFloor tPlaceFloor) {
        tPlaceFloor.setCreateTime(new Date().toString());
        boolean flag = tPlaceFloorService.saveFloor(tPlaceFloor);
        return CommonResult.success(flag);
    }

    @ApiOperation("getFloorById =>  根据id查询楼层信息")
    @GetMapping("/getFloorById/{id}")
    public CommonResult getFloorById(@PathVariable Long id) {
        TPlaceFloor byId = tPlaceFloorService.getById(id);
        return CommonResult.success(byId);
    }
    @ApiOperation("deleteFloorByid =>  删除楼层")
    @GetMapping("/deleteFloorByid/{id}")
    public CommonResult deleteFloorByid(@PathVariable Long id) {
        boolean flag = tPlaceFloorService.deleteFloorById(id);
        return CommonResult.success(flag);
    }


    @ApiOperation("updateFloor =>  修改楼层")
    @PutMapping("/updateFloor")
    public CommonResult updateFloor(@RequestBody TPlaceFloor tPlaceFloor) {
        tPlaceFloor.setUpdateTime(new Date().toString());
        boolean flag = tPlaceFloorService.updateFloor(tPlaceFloor);
        if (flag) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }


}
